package JZOffer;

import java.util.HashMap;
import java.util.Map;

// 复杂链表的复制
public class JzOffer35 {
    public Node copyRandomList(Node head) {
        Map<Node, Node> map = new HashMap<>();

        Node cur = head;
        while (cur != null) {
            Node node = new Node(cur.val);
            map.put(cur, node);
            cur = cur.next;
        }
        cur = head;

        while (cur != null) {
           map.get(cur).random = map.get(cur.random);
           map.get(cur).next = map.get(cur.next);
           cur = cur.next;
        }
        return map.get(head);
    }
}

